using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using MOM.DB.Access;
using Mono.Data.Sqlite;

namespace MOM.DB
{
	public partial class SqlConsole : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsAdmin)
			{
				Response.Write("<html><h1>Unauthorized!</h1></html");
				Response.End();
			}
		}

		protected void SQL_Click(object sender, EventArgs e)
		{
			using (SqliteServer conn = new SqliteServer("Default", true))
			{
				bool success = true;
				try
				{
					conn.Execute(txtSQL.Text);
				}
				catch (Exception x)
				{
					success = false;
					lblError.CssClass = "Error";
					lblError.Text = "Error: " + x.Message;				
				}

				if (success)
				{
					lblError.CssClass = "Success";
					lblError.Text = "Successfully executed statement.";
				}
			}

			DataBind();
		}
	}
}
